﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Directory类操作
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"D:\My\.Net Project\文件操作\Directory类操作";

            /*基础操作*/
            //Exists(path);
            //Delete(path);
            //CreateDirectory(path);
            //GetFiles(path);
            //GetGetDirectories(path);
            //GetCurrentDirectory();
            //Move(path);  
            //GetLogicalDrives();

            Console.ReadKey();
        }

        static void Exists(string path)
        {
            Console.WriteLine(Directory.Exists(path));
        }
        static void Delete(string path)
        {
            Directory.Delete(path);
        }
        static void CreateDirectory(string path)
        {             
            Directory.CreateDirectory(path);
        }
        /// <summary>
        /// 读取所有文件的路径
        /// </summary>
        /// <param name="path"></param>
        static void GetFiles(string path)
        {
            string[] files = Directory.GetFiles(path);
            foreach (var file in files)
            {
                Console.WriteLine(file);
            }
        }
        /// <summary>
        /// 读取所有的文件(包括子文件)
        /// </summary>
        /// <param name="path"></param>
        static void GetGetDirectories(string path)
        {
            string[] files = Directory.GetDirectories(path);
            foreach (var file in files)
            {
                Console.WriteLine(file);
            }
        } 
        /// <summary>
        /// 得到程序的工作路径
        /// </summary>
        static void GetCurrentDirectory()
        {
            Console.WriteLine(Directory.GetCurrentDirectory());
        }
        /// <summary>
        /// 移动文件(改文件名字用的)
        /// </summary>
        static void Move(string path)
        {                        //目标路径最后一个路径必须是空的Testb,程序会自动创建此文件夹
            Directory.Move(path, @"D:\My\Testb");
        }
        /// <summary>
        /// 得到磁盘
        /// </summary>
        static void GetLogicalDrives()
        {
            string[] strs = Directory.GetLogicalDrives();
            foreach (var str in strs)
            {
                Console.WriteLine(str);
            }
        }
    }
}
